
Rsd.define('Rsd.Faith.pages.BankCunKuanJiHuaListPage', {
    extend: 'Rsd.Faith.pages.ListPage',
    requires: ['Rsd.controlEx.ComboBoxEnum'],
    xtype: 'list-jiexijihua',
    border: false,
    tabTitle: '分户账户余额',
    searchColumns:[{name:'SuoShuQi',text:'所属期'}],
    newButtons:[{text:'新增结息计划',handler:'editItem'}],
    modelType: 'BankCunKuanJiHuaModel',
    readOnly:false,
    sort:[{name:'KaiShiRiQi',direction:'desc'}],
    formFields: [
        {
            "name": "SuoShuQi",
            "label": {
                "width": 80,
                "content": "所属期"
            },
            "dataIndex": "SuoShuQi",
            "index": 22,
            "exist": true,
            "xtype": "text",
            "length": 255
        },
        {
            "name": "KaiShiRiQi",
            "label": {
                "width": 80,
                "content": "开始日期"
            },
            "dataIndex": "KaiShiRiQi",
            "index": 23,
            "exist": true,
            "xtype": "text",
            "length": 256
        },
        {
            "name": "JieShuRiQi",
            "label": {
                "width": 80,
                "content": "结束日期"
            },
            "dataIndex": "JieShuRiQi",
            "index": 24,
            "exist": true,
            "xtype": "text",
            "length": 256
        },
        {
            "name": "DingQiLiLv",
            "label": {
                "width": 80,
                "content": "定期年利率"
            },
            "dataIndex": "DingQiLiLv",
            "index": 26,
            "exist": true,
            "xtype": "number",
            "precision": 3
        },
        {
            "name": "HuoQiLiLv",
            "label": {
                "width": 80,
                "content": "活期年利率"
            },
            "dataIndex": "HuoQiLiLv",
            "index": 28,
            "exist": true,
            "xtype": "number",
            "precision": 3
        },
        {
            "name": "DingCunBiLv",
            "label": {
                "width": 80,
                "content": "定存比例(%)"
            },
            "dataIndex": "DingCunBiLi",
            "index": 30,
            "exist": true,
            "xtype": "number",
            "precision": 0
        },
        {
            "name": "ZhuangTai",
            "label": {
                "width": 80,
                "content": "状态"
            },
            "dataIndex": "ZhuangTai",
            "index": 40,
            "exist": true,
            "xtype": "combobox-enum",
            enum:[{text:'未到期',value:'未到期'},{text:'待结息',value:'待结息'},{text:'已提交',value:'已提交'},{text:'已结息',value:'已结息'}],
            "length": 10
        },
        {
            "name": "Remark",
            "label": {
                "width": 80,
                "content": "备注"
            },
            "dataIndex": "Remark",
            "index": 200,
            "exist": true,
            "xtype": "text",
            "length": 100
        }
    ],
    gridColumns: [
        {
            "text": "序号",
            "xtype": "index",
            "width": 40,
            "index": 0,
            "deep": 1
        },
        {
            "name": "SuoShuQi",
            "dataIndex": "SuoShuQi",
            "sortable": false,
            "text": "所属期",
            "index": 22,
            "exist": true,
            "xtype": "string",
            "width": 60,
            "nobr": true,
            "deep": 1
        },
        {
            "name": "KaiShiRiQi",
            "dataIndex": "KaiShiRiQi",
            "sortable": false,
            "text": "开始日期",
            "index": 23,
            "exist": true,
            "xtype": "date",
            "width": 100,
            "nobr": true,
            "deep": 1
        },
        {
            "name": "JieShuRiQi",
            "dataIndex": "JieShuRiQi",
            "sortable": false,
            "text": "结束日期",
            "index": 24,
            "exist": true,
            "xtype": "date",
            "width": 100,
            "nobr": true,
            "deep": 1
        },
        {
            "name": "DingQiLiLv",
            "dataIndex": "DingQiLiLv",
            "sortable": false,
            "text": "定期年利率",
            "index": 26,
            "exist": true,
            "xtype": "number",
            "width": 100,
            "precision": 3,
            "deep": 1
        },
        {
            "name": "HuoQiLiLv",
            "dataIndex": "HuoQiLiLv",
            "sortable": false,
            "text": "活期年利率",
            "index": 28,
            "exist": true,
            "xtype": "number",
            "width": 100,
            "precision": 3,
            "deep": 1
        },
        {
            "name": "DingCunBiLv",
            "dataIndex": "DingCunBiLi",
            "sortable": false,
            "text": "定存比例(%)",
            "index": 30,
            "exist": true,
            "xtype": "number",
            "width": 70,
            "precision": 0,
            "deep": 1
        },
        {
            "name": "YingJieLiXi",
            "dataIndex": "YingJieLiXi",
            "sortable": false,
            "text": "应结利息",
            "index": 30,
            "exist": true,
            "xtype": "number",
            "total":true,
            "width": 100,
            "precision": 2,
            "deep": 1
        },
        {
            "name": "YiJieLiXi",
            "dataIndex": "YiJieLiXi",
            "sortable": false,
            "text": "已结利息",
            "index": 30,
            "exist": true,
            "xtype": "number",
            "total":true,
            "width": 100,
            "precision": 2,
            "deep": 1
        },
        {
            "name": "ZhuangTai",
            "dataIndex": "ZhuangTai",
            "sortable": false,
            "text": "状态",
            align:'center',
            format:'format_ZhuangTai',
            "index": 40,
            "exist": true,
            "xtype": "enum",
            "enum": {
                "name": "Rsd.Faith.Core.CunKuanZhuangTai",
                 valueMember:'Code',
                 textMember:'Text',
                "items": [
                    {
                        "Code": "DJ",
                        "Text": "已登记",
                        "Value": 0
                    },
                    {
                        "Code": "YC",
                        "Text": "已计息",
                        "Value": 1
                    },
                    {
                        "Code": "HS",
                        "Text": "已结息",
                        "Value": 2
                    },
                    {
                        "Code": "JX",
                        "Text": "已入账",
                        "Value": 3
                    }
                ]
            },
            "width": 100,
            "nobr": true,
            "deep": 1
        },
        {
            "name": "Remark",
            "dataIndex": "Remark",
            "sortable": false,
            "text": "备注",
            "index": 100,
            "exist": true,
            "xtype": "string",
            "width": 50,
            "nobr": true,
            "deep": 1
        }
    ],
    titleField : 'SuoShuQi',
    templateCols: [
        {
            name: 'edit',
            text: '操 作',
            nobr:true,
            xtype: 'template',
            format:'templateFormat'
        },
        {
            name: 'space',
            text: '',
            xtype: 'template',
            width: 5,
            hideable: false,
            sortable: false
        }
    ],
    /*
     * */
    constructor: function (config) {
        config = config || {};
        Rsd.apply(this, config);
    },
    /*
    * */
    format_ZhuangTai:function format_ZhuangTai(row)
    {
        var btns = [];
        if(new Date(row['JieShuRiQi']).getTime() > new Date().getTime())
        {
            btns.push(Rsd.newLine());
            btns.push(Rsd.text('[未到期]','red'));

        }
        return btns;
    },
    /*
    * */
    templateFormat:function templateFormat(row){

        var me = this;
        var btns = [Rsd.blankspan(2)];


        if(row['ZhuangTai'] == 'DJ')
        {
            //
            btns.push(Rsd.blankspan(1));

            btns.push(Rsd.button('更新利率',function () {
                Rsd.showWaiting(me.id);
                Rsd.app.requestService('bank.synlilv',{key:row['Id']},function (data) {
                   console.log(data);

                    Rsd.closeWaiting(me.id)
                });
            }));
            btns.push(Rsd.blankspan(1));

            btns.push(Rsd.button('存款计息',function () {
                Rsd.showWaiting(me.id);
                Rsd.app.requestService('bank.FenHuCunKuan',{key:row['Id']},function (data) {

                    if(data.success)
                    {
                        Rsd.alert('执行存款成功');
                        me.load();
                    }else
                    {
                        Rsd.alert(data.msg);
                    }
                    Rsd.closeWaiting(me.id)
                });
            }));

        }
        if(row['ZhuangTai'] == 'YC')
        {
            btns.push(Rsd.blankspan(1));

            btns.push(Rsd.button('查看详情',function () {
                Rsd.create('Rsd.Faith.dialogs.BankFenHuShouYiListDialog',{suoShuQi:row['SuoShuQi'],title:row['SuoShuQi'] + '分户存款计息明细'}).showDialog();
            },null,null,{backgroundColor:'grey',borderColor: 'black'}));

            btns.push(Rsd.blankspan(1));

            btns.push(Rsd.button('利息核算',function () {
                Rsd.showWaiting(me.id);
                Rsd.app.requestService('bank.LiXiHeSuan',{key:row['Id']},function (data) {

                    if(data.success)
                    {
                        Rsd.alert('执行存款成功');
                        me.load();
                    }else
                    {
                        Rsd.alert(data.msg);
                    }
                    Rsd.closeWaiting(me.id)
                });;

            }));

        }
        if(row['ZhuangTai'] == 'HS')
        {
            btns.push(Rsd.button('查看详情',function () {

                Rsd.create('Rsd.Faith.dialogs.BankFenHuShouYiListDialog',{suoShuQi:row['SuoShuQi'],title:row['SuoShuQi'] + '分户存款计息明细'}).showDialog();

            },null,null,{backgroundColor:'grey',borderColor: 'black'}));

            btns.push(Rsd.blankspan(1));

            btns.push(Rsd.button('结息入账',function () {
                Rsd.showWaiting(me.id);
                //

                Rsd.app.requestService('system.NewTimer',
                    {
                       list: [
                                {path:'bank/JieXiRuZhang?key=' +row['Id'],group:'FHJX' + row['Id'],text:row['SuoShuQi'] + '期存款计划结息入分户账'},
                                {path:'bank/FenHuLiXiHeSuan?key=' +row['Id'],group:'FHJX' + row['Id'],text:row['SuoShuQi'] +  '各账户分户利息合计金额核算'},
                                {path:'bank/FenHuLiXiShuQiHeSuan?key=' +row['Id'],group:'FHJX' + row['Id'],text: row['SuoShuQi'] +  '期账目分户利息合计金额核算'}
                            ]
                    },
                    function (data) {
                        if(data.success)
                        {
                            Rsd.alert('结息任务已提交');

                        }else
                        {
                            Rsd.alert(data.msg);
                        }
                        Rsd.closeWaiting(me.id)
                      },
                    10000);
            }));

        }
        if(row['ZhuangTai'] == 'JX')
        {
            btns.push(Rsd.button('查看详情',function () {
                Rsd.create('Rsd.Faith.dialogs.BankFenHuShouYiListDialog',{suoShuQi:row['SuoShuQi'],title:row['SuoShuQi'] + '分户存款计息明细'}).showDialog();

            },null,null,{backgroundColor:'grey',borderColor: 'black'}));
        }
        return btns;
    }



});